// 引入Vue 引入路由 使用路由
import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter)

// 引入路由
import HomePage from '@/views/HomePage/HomePage'
import CategoryPage from '@/views/CategoryPage/CategoryPage'
import DiscoverPage from '@/views/DiscoverPage/DiscoverPage'
import CarPage from '@/views/CarPage/CarPage'
import MinePage from '@/views/MinePage/MinePage'
import CategoryList from '@/views/CategoryList/CategoryList'

// 创建路由实例 路由规则
const router = new VueRouter({
  routes: [
    {
      path: '/',
      redirect: '/homepage'
    },
    {
      path: '/homepage',
      component: HomePage,
      meta: { showTabbar: true }
    },
    {
      path: '/categorypage',
      component: CategoryPage,
      meta: { showTabbar: true }
    },
    {
      path: '/discoverpage',
      component: DiscoverPage,
      meta: { showTabbar: true }
    },
    {
      path: '/carpage',
      component: CarPage,
      meta: { showTabbar: true }
    },
    {
      path: '/minepage',
      component: MinePage,
      meta: { showTabbar: false }
    },
    {
      path: '/categorylist/:cat_id',
      component: CategoryList,
      meta: { howTabbar: false }
    },
    {
      path: '/loginpage',
      //路由懒加载，只有用户进行登录操作时才会加载这个页面
      component: () => import('@/views/LoginPage/LoginPage.vue'),
      //meta: { showTabbar: false }
    },
    {
      path: '/searchpage',
      component: () => import('@/views/SearchPage/SearchPage.vue'),
      meta: { showTabbar: true }
    },
    {
      path: '/register',
      component: () => import('@/views/RegisterPage/RegisterPage.vue'),
    },
    {
      path: '/forgetpwd',
      component: () => import('@/views/ForgetPwd/ForgetPwd.vue')
    },
    {
      path: '/goods/:goods_id',
      name: 'goodsdetail',
      component: () => import('@/views/GoodsPage/GoodsPage.vue')
    }]
});

// 多次点击同一个路由解决方案
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};

// 暴露路由实例
export default router